package com.lw.extraceim.loader;

import android.content.Context;

import androidx.annotation.NonNull;

import com.lw.extraceim.app.AppConstants;
import com.lw.extraceim.loader.base.BaseLoader;
import com.lw.extraceim.model.TransPackage;
import com.lw.extraceim.util.JsonUtils;
import com.zhy.http.okhttp.callback.Callback;


/**
 * @Author : liwei
 * @Email : 1759840027@qq.com
 * @Description : 包裹信息的加载类
 * @Date : 2019/5/10 17:03
 */
public class PackageLoader extends BaseLoader {

    public PackageLoader(Context context) {
        super(context);
    }


    /**
     * 保存包裹信息
     *
     * @param transPackage
     * @param callback
     */
    public void save(@NonNull TransPackage transPackage, @NonNull Integer userId, @NonNull Callback callback) {
        String url = AppConstants.PACKAE_SERVICE + "/save/" + userId;
        String jsonPackage = JsonUtils.toJson(transPackage);
        execute(url, jsonPackage, callback);
    }

    /**
     * 通过包裹编号获取包裹信息
     *
     * @param packageId
     * @param callback
     */
    public void get(String packageId, @NonNull Callback callback) {
        String url = AppConstants.PACKAE_SERVICE + "/get_package/" + packageId;
        execute(url, AppConstants.GET, null, callback);
    }

    /**
     * 修改包裹信息
     *
     * @param transPackage
     * @param callback
     */
    public void update(@NonNull TransPackage transPackage, @NonNull Callback callback) {
        String url = AppConstants.PACKAE_SERVICE + "/update";
        String jsonPackage = JsonUtils.toJson(transPackage);
        execute(url, jsonPackage, callback);
    }

    /**
     * 将快件移动到包裹中
     *
     * @param packageId
     * @param esId
     * @param callback
     */
    public void moveESInToPackage(String packageId, String esId, @NonNull Callback callback) {
        String url = AppConstants.PACKAE_SERVICE + "/move_es_in/" + packageId + "/" + esId;
        execute(url, AppConstants.GET, null, callback);
    }

    /**
     * 将快件移出包裹
     *
     * @param packageId
     * @param esId
     * @param callback
     */
    public void moveEsOutPackage(String packageId, String esId, @NonNull Callback callback) {
        String url = AppConstants.PACKAE_SERVICE + "/move_out_es/" + packageId + "/" + esId;
        execute(url, AppConstants.GET, null, callback);
    }

    /**
     * 拆包
     *
     * @param packageId
     * @param userId
     */
    public void uppake(String packageId, Integer userId, @NonNull Callback callback) {
        String url = AppConstants.PACKAE_SERVICE + "/unpack/" + packageId + "/" + userId;
        execute(url, AppConstants.GET, null, callback);
    }

    /**
     * 获取由userID 操作为 operation 状态为 status的包裹信息
     *
     * @param userId
     * @param operation
     * @param status
     * @param callback
     */
    public void getPackageListByUserId(Integer userId, Integer operation, Integer status, @NonNull Callback callback) {
        String url = AppConstants.PACKAE_SERVICE + "/getPackageList/" + userId + "/" + operation + "/" + status;
        execute(url, AppConstants.GET, null, callback);
    }

    /**
     * 拆包
     *
     * @param packageId
     * @param userId
     * @param callback
     */
    public void unpack(String packageId, Integer userId, @NonNull Callback callback) {
        String url = AppConstants.PACKAE_SERVICE + "/unpack/" + packageId + "/" + userId;
        execute(url, AppConstants.GET, null, callback);
    }

    /**
     * 转运包裹
     *
     * @param packageId
     * @param userId
     * @param callback
     */
    public void transportPackage(String packageId, Integer userId, @NonNull Callback callback) {
        String url = AppConstants.PACKAE_SERVICE + "/transporOrRecevice/transport/" + packageId + "/" + userId;
        execute(url, AppConstants.GET, null, callback);
    }

    /**
     * 接收包裹
     *
     * @param packageId
     * @param userId
     * @param callback
     */
    public void receivePackage(String packageId, Integer userId, @NonNull Callback callback) {
        String url = AppConstants.PACKAE_SERVICE + "/transporOrRecevice/receive/" + packageId + "/" + userId;
        execute(url, AppConstants.GET, null, callback);
    }

    /**
     * 获取用户正在转运的包裹
     *
     * @param userId
     * @param callback
     */
    public void getTransportintPackage(Integer userId, @NonNull Callback callback) {
        String url = AppConstants.PACKAE_SERVICE + "/transportingpackage/" + userId;
        execute(url, AppConstants.GET, null, callback);
    }

    /**
     * 查询用户是否正在运送包裹
     *
     * @param userId
     * @param callback
     */
    public void isTransporting(Integer userId, @NonNull Callback callback) {
        String url = AppConstants.PACKAE_SERVICE + "/isTransporting/" + userId;
        execute(url, AppConstants.GET, null, callback);
    }

}
